$(function(){
    console.log('jjjjjj');



     $('#XinZeng').click(function(){
        console.log('点击了新增');
        window.location.href='/Product/CreateOrEdit'
    })

    $('#BaoCun').click(function(){
        console.log('点击了保存');

        let Id=$('[name=Id]').val();
        let ProductName=$('[name=ProductName]').val();
        let Supplier=$('[name=Supplier]').val();
        let Price=$('[name=Price]').val();
        let Stock=$('[name=Stock]').val();
        let Remarks=$('[name=Remarks]').val();

        let obj={
            Id,
            ProductName,
            Supplier,
            Price,
            Stock,
            Remarks
        }
        $.post('/Product/BaoCun',obj,function(){
            window.location.href='/Product/Index'
        })   
    })


        $('#ChaZhao').click(function(){
            
            let KeyWork=$('[name=KeyWork]').val();
    
            let obj={
                KeyWork
            }

            $('.table').html('')

            $.post('/Product/Query',obj,function(res){
                console.log(res);
                res.forEach(item => {
                    let html=`
                    <tr class="table">
                     <td>${item.id}</td>
                     <td>${item.productName}</td>
                     <td>${item.supplier}</td>
                     <td>${item.price}</td>
                     <td>${item.stock}</td>
                     <td>${item.remarks}</td>
                     <td>
                         <input type="button" value="编辑" onclick="btnEdit(${item.id})">
                         <input type="button" value="删除" onclick="btnDele(${item.id})">
                     </td>
                 </tr>
                    `
                    $('#Tb').append(html);
                });
            })    
        })   

})




    $('#QuXiao').click(function(){
        console.log('点击了取消');
        window.location.href='/Product/Index'
    })



function btnEdit(id){
    console.log('点击了编辑');
    window.location.href=`/Product/CreateOrEdit/${id}`
}


function btnDele(id){
    console.log('点击了删除');
    if(confirm('确定删除吗？亲？')){
    window.location.href=`/Product/Delete/${id}`
    }
}